package com.xframe.event.bus.core.msg;


import com.xframe.event.bus.core.annotation.ReceiveMsgArgs;

/**
 * 接收器工厂
 */
public class ReceiveMsgFactory {

    public static IReceiveMsg create(ReceiveMsgArgs receiveMsgArgs,IMsgProc msgProc) {
        return create(receiveMsgArgs.getMsgMode(),msgProc,receiveMsgArgs.getExchange(),receiveMsgArgs.getQueue(),
                receiveMsgArgs.getRoutingKey(),receiveMsgArgs.getQos(),receiveMsgArgs.isAutoAck());
    }

    public static IReceiveMsg create(MsgMode msgMode, IMsgProc msgProc, String exchange, String queueName, String routingKey, int qos, boolean autoAck) {

        IReceiveMsg receiveMsg = null;
        switch (msgMode) {
            case DEFMODE:
                receiveMsg = new DefReceiveMsg(ConnectFactory.getMsgConn(), msgProc, queueName, qos, autoAck);
                break;
            case FANOUT:
                receiveMsg = new FanoutReceiveMsg(ConnectFactory.getMsgConn(), msgProc, queueName, exchange);
                break;
            case DIRECT:
                receiveMsg = new DirectReceiveMsg(ConnectFactory.getMsgConn(), msgProc, queueName, exchange, routingKey);
                break;
            case TOPIC:
                receiveMsg = new TopicReceiveMsg(ConnectFactory.getMsgConn(), msgProc, queueName, exchange, routingKey);
                break;
        }
        return receiveMsg;
    }

    public static IReceiveMsg createDefReceiveMsg(IMsgProc msgProc, String queueName, int qos, boolean autoAck) {
        return create(MsgMode.DEFMODE, msgProc, "", queueName, "", qos, autoAck);
    }

    public static IReceiveMsg createDefReceiveMsg(IMsgProc msgProc, String queueName) {
        return createDefReceiveMsg(msgProc, queueName, 1, true);
    }

    public static IReceiveMsg createFanoutReceiveMsg(IMsgProc msgProc, String exchange, String queueName) {
        return create(MsgMode.FANOUT, msgProc, exchange, queueName, "", 1, true);
    }

    public static IReceiveMsg createDirectReceiveMsg(IMsgProc msgProc, String exchange, String queueName, String routingKeys) {
        return create(MsgMode.DIRECT, msgProc, exchange, queueName, routingKeys, 1, true);
    }

    public static IReceiveMsg createTopicReceiveMsg(IMsgProc msgProc, String exchange, String queueName, String routingKeys) {
        return create(MsgMode.TOPIC, msgProc, exchange, queueName, routingKeys, 1, true);
    }


}
